package com.ruoyi.pressure.controller;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pressure.domain.KyLaneDblcHistory;
import com.ruoyi.pressure.service.IKyLaneDblcHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 顶板离层测点实时信息数据项说明Controller
 * 
 * @author lth
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/pressure/dblcHistory")
public class KyLaneDblcHistoryController extends BaseController
{
    @Autowired
    private IKyLaneDblcHistoryService kyLaneDblcHistoryService;

    /**
     * 查询顶板离层测点实时信息数据项说明列表
     */
    @PreAuthorize("@ss.hasPermi('pressure:dblcHistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(KyLaneDblcHistory kyLaneDblcHistory)
    {
//        startPage();
//        List<KyLaneDblcHistory> list = kyLaneDblcHistoryService.selectKyLaneDblcHistoryList(kyLaneDblcHistory);
//        return getDataTable(list);
        List<KyLaneDblcHistory> list = kyLaneDblcHistoryService.selectKyLaneDblcHistoryList(kyLaneDblcHistory);

        TableDataInfo rspData = new TableDataInfo();
        Integer total = Math.toIntExact(list.size());
        rspData.setCode(200);
        rspData.setTotal(total);
        rspData.setMsg("查询成功");

        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        list = list.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        rspData.setRows(list);

        return rspData;
    }

    /**
     * 导出顶板离层测点实时信息数据项说明列表
     */
    @PreAuthorize("@ss.hasPermi('pressure:dblcHistory:export')")
    @Log(title = "顶板离层测点实时信息数据项说明", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KyLaneDblcHistory kyLaneDblcHistory)
    {
        List<KyLaneDblcHistory> list = kyLaneDblcHistoryService.selectKyLaneDblcHistoryList(kyLaneDblcHistory);
        ExcelUtil<KyLaneDblcHistory> util = new ExcelUtil<KyLaneDblcHistory>(KyLaneDblcHistory.class);
        util.exportExcel(response, list, "顶板离层测点实时信息数据项说明数据");
    }

    /**
     * 获取顶板离层测点实时信息数据项说明详细信息
     */
    @PreAuthorize("@ss.hasPermi('pressure:dblcHistory:query')")
    @GetMapping(value = "/{kyLaneDblcRealId}")
    public AjaxResult getInfo(@PathVariable("kyLaneDblcRealId") String kyLaneDblcRealId)
    {
        return success(kyLaneDblcHistoryService.selectKyLaneDblcHistoryByKyLaneDblcRealId(kyLaneDblcRealId));
    }

    /**
     * 新增顶板离层测点实时信息数据项说明
     */
    @PreAuthorize("@ss.hasPermi('pressure:dblcHistory:add')")
    @Log(title = "顶板离层测点实时信息数据项说明", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KyLaneDblcHistory kyLaneDblcHistory)
    {
        return toAjax(kyLaneDblcHistoryService.insertKyLaneDblcHistory(kyLaneDblcHistory));
    }

    /**
     * 修改顶板离层测点实时信息数据项说明
     */
    @PreAuthorize("@ss.hasPermi('pressure:dblcHistory:edit')")
    @Log(title = "顶板离层测点实时信息数据项说明", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KyLaneDblcHistory kyLaneDblcHistory)
    {
        return toAjax(kyLaneDblcHistoryService.updateKyLaneDblcHistory(kyLaneDblcHistory));
    }

    /**
     * 删除顶板离层测点实时信息数据项说明
     */
    @PreAuthorize("@ss.hasPermi('pressure:dblcHistory:remove')")
    @Log(title = "顶板离层测点实时信息数据项说明", businessType = BusinessType.DELETE)
	@DeleteMapping("/{kyLaneDblcRealIds}")
    public AjaxResult remove(@PathVariable String[] kyLaneDblcRealIds)
    {
        return toAjax(kyLaneDblcHistoryService.deleteKyLaneDblcHistoryByKyLaneDblcRealIds(kyLaneDblcRealIds));
    }
}
